from time import sleep, time
import threading


def sing():
    print("start sing...")
    sleep(2)
    print("end sing...")


def dance():
    print("start dance...")
    sleep(4)
    print("end dance...")


if __name__ == "__main__":
    t1 = threading.Thread(target=sing)
    t2 = threading.Thread(target=dance)

    # 设置为守护线程, 随着主线程结束而结束
    # t1.setDaemon(True)
    # t2.setDaemon(True)

    start_time = time()
    t1.start()
    t2.start()

    # 等待所有线程结束, 才执行后面的代码
    t1.join()
    t2.join()

    end_time = time()
    print(f"last time: {end_time - start_time}")
